$(function(){
   $.ajax({
       type     : 'POST',
       url      : 'dbcheck.php',
       data     : {dataoption : 'table'},
       datatype : 'html',
       success : function(response){
           $('#productname').append(response);
       }
   });
   $('#productname').on('change',function(){
       $(this).after("<button type='button' id='deletecsv'>Delete this csv from database</button>");
   });
   
   $(document).on('click','#deletecsv',function(){
       console.log("here");
       $.ajax({
         type     : 'POST',
         url      : 'addqa.php',
         data     : {dataoption : 'deletecsv',csvname : $('#productname :selected').val()},
         success : function(response){
            $('#productname').append(response);
         }
       });
       $('#productname :selected').remove();
       $(this).remove();
   });
   
     $("#answer").on('change',function(){
       var answer = document.getElementById('answer').value;
       if(answer=="box")
       {
        $('#email,#subqoptions').hide();       
        $('#msg').show(); 
        //$('.box').append("<div id='msg'><label>Voer antwoord te worden gegeven</label><textarea cols='5' rows='5'></textarea></div>");
       }
       else if(answer=="email")
       {
        $('#msg,#subqoptions').hide();
        $('#email').show();
       
       }
       else if(answer=="dropdown")
       {
        $('#msg,#email').hide();
        $('#subqoptions').show();
       }
   });
   $('#addsubq').on('click',function(){
       var counter1 = ($('.subqoption :last').attr('id')).slice(10);
       //console.log(counter1);
       counter1++;
       $('#subqoptions').append("<span><input class='subqoption' id='subqoption"+counter1+"' name='subqoption[]' placeholder='Subquestion option"+counter1+"'/></span>");
   });
   $('#addqdone').on('click',function(){
       $('#subansweroptions').show();
   });
   $('#addsubanswer').on('click',function(){
       var counter2 = ($('.subansweroption :last').attr('id')).slice(15);
       //console.log(counter2);
       counter2++;
       $('#subansweroptions').append("<span><textarea class='subansweroption' id='subansweroption"+counter2+"' name='subansweroption[]' placeholder='Subanswer option"+counter2+"' cols='10'></textarea></span>");
   });
});
